<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<link rel="stylesheet" href="${ctx}/static/js/lib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${ctx}/static/js/lib/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${ctx}/static/js/lib/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript">
var _rs_image_path = _ctx+"/static/images";
var localNodeId = '${localNode.id}';	
var slAuthFlag = '${sessionScope._user_session.slAuthFlag}';
$(function() {
	getLocalNode();
	$("#localNodeId").val(localNodeId);
})
	function getLocalNode(){
		$.ajax({
			   type: "GET",
			   dataType:"html",
			   cache: false,
			   url: _ctx + "/registry/node_info_get.do",
			   data: {id:localNodeId},
			   success: function( content ){
				   $('#data').html( content ); 
			   },
			   error:function(){
				   ui.msg('信息加载错误', 0);
			   }
		});
	}
	/**
	 *文档加载完成后执行
	 */
	 var nodeSetting = {
			 	async: {
					enable: true,
					url: _ctx + "/registry/node_info_tree.do",
					autoParam: ["id"],
					dataFilter: filter
				},
				view: {
					fontCss: getFont,
					nameIsHTML: true,
					selectedMulti: false
				},
				check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				 callback: {
		                onCheck: zTreeOnCheck,
		                onClick:getNodeInfo
		           }
			};
	 var zNodes = ${treeData};
	 var zTree;
	 $(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), nodeSetting, zNodes);
			zTree = $.fn.zTree.getZTreeObj("treeDemo");
		});
	function zTreeOnCheck(event, treeId, treeNode) {
	    zTree.expandNode(treeNode, true);
	}
	function filter(treeId, parentNode, childNodes) {
		var args = window.dialogArguments;
		if (!childNodes) return null;
		var regionCodesToMgr = "${permission.regionCodesToMgr}";
		for (var i=0, l=childNodes.length; i<l; i++) {
			childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			
		}
		
		return childNodes;
	}
	
	/**
	 * 返回设置结果
	 */
	 function cfgwindow(){
		var checkedNodes = zTree.getCheckedNodes(true);
		var arrayIds = new Array();
		var arrayNames = new Array();
		for(var i in checkedNodes){
			if(checkedNodes[i].type!='1'){
				arrayIds.push(checkedNodes[i].id);
				arrayNames.push(checkedNodes[i].name)
			}
		}
		var ids =arrayIds.join(",");
		
	    var names=arrayNames.join(",");
	    window.returnValue = ids +"|"+names;
		window.close();
	}
	function getNodeInfo(event, treeId, treeNode) {
		var nodeId = treeNode.id;
		var pid = treeNode.pId;
		var isAdd = treeNode.isAdd;
		var isEdit = treeNode.isEdit;
		var netType = treeNode.netType;
		var orgCode = treeNode.orgCode;
		$("#nodeId").val(nodeId);
		$("#pid").val(pid);
		$("#nodeNetType").val(netType);
		var ismgr = "${ismgr}";
		if(slAuthFlag !='4'){
			if(ismgr =="1" && isAdd =="1"){
				$("#add").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
			}else{
				$("#add").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
			}
			var regionCodesToMgr = "${permission.regionCodesToMgr}";
			 if( ismgr == "1"  && isEdit =="1" ){
					$("#edit").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
					if(netType != pid){
						$("#del").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
					}else{
						$("#del").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
					}
			}else{
					$("#edit").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
					$("#del").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
			}
		}
		 if(treeNode.orgCode != ""){
			 $.ajax({
				   type: "GET",
				   dataType:"html",
				   cache: false,
				   url: _ctx + "/registry/node_info_get.do",
				   data: {id:treeNode.id},
				   success: function( content ){
					   $('#data').html( content ); 
				   },
				   error:function(){
					   ui.msg('信息加载错误', 0);
				   }
			});
		 }
	}
	function nodeAdd(){
		if("${permission.regionCodesToMgr}" == ""){
			 ui.msg('无管理范围的节点', 0);
		}else{
			$.ajax({
				   type: "GET",
				   dataType:"html",
				   cache: false,
				   url: _ctx + "/registry/node_info_add.do",
				   data: {nodeNetType:$("#nodeNetType").val(),pid:$("#pid").val()},
				   success: function( content ){
					   $('#data').html( content ); 
				   },
				   error:function(){
					   ui.msg('信息加载错误', 0);
				   }
			});
		}
	}
	function nodeUpdate(){
		$.ajax({
			   type: "GET",
			   dataType:"html",
			   cache: false,
			   url: _ctx + "/registry/node_info_update.do",
			   data: {id:$("#nodeId").val()},
			   success: function( content ){
				   $('#data').html( content ); 
			   },
			   error:function(){
				   ui.msg('信息加载错误', 0);
			   }
		});
	}
	function nodeDel(){
		ui.confirm('确认删除?',function(){
			$("#del").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
			$("#edit").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
			$.ajax({
				   type: "POST",
				   dataType:"json",
				   cache: false,
				   url: _ctx + "/registry/node_info_delete.do",
				   data: {id:$("#nodeId").val()},
				   success: function( resp ){
					   if (resp.status == '1') {
							ui.msg(resp.msg, 1);
							ui.go(_ctx + '/registry/node_info_mgr.do');
						} else {
							ui.msg(resp.msg, 0);
						}
				   },
				   error:function(){
					   $("#del").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
					   $("#edit").removeClass("btn-primary").addClass("btn-light").attr("disabled", null);
					   ui.msg('信息加载错误', 0);
				   }
			});
		});	
	}
	function getFont(treeId, node) {
		var temp = node.font ? node.font : {};
		return temp
	}

</script>
<style type="text/css">
	div.zTreeDemoBackground {width:auto;height:440px;text-align:left;}
	ul.ztree {margin-top: 10px;border: 1px solid #CCC;height:400px;overflow-y:auto;overflow-x:auto;font-size: 13px;}
	.ztree * {
		padding: 0;
		margin: 0;
		font-size: 13px;
		font-family: Verdana, Arial, Helvetica, AppleGothic, sans-serif;
	}
	.ztree li span {
		line-height: 24px;
		margin-right: 2px;
	}
	.ztree li span.button.switch {
		width: 18px;
		height: 22px;
	}
	.ztree li a {
	height: 24px;
	}
	.ztree li a.curSelectedNode {
	height: 24px;
	}
	
	.ztree li span.button {
		line-height: 0;
		margin: 0;
		width: 24px;
		height: 24px;
		display: inline-block;
		border: 0 none;
		cursor: pointer;
		outline: none;
	}
	
		
	@media only screen and (max-width:992px) {
		.profile-info-name {
			width: 80px
		}
		.profile-info-value {
			margin-left: 90px
		}
		.profile-user-info-striped .profile-info-name {
			position: static;
			width: auto;
			text-align: left;
			padding: 6px 0 6px 10px
		}
		.profile-user-info-striped .profile-info-value {
			margin-left: 10px
		}
	}
	
	@media only screen and (max-width:992px) {
		.user-profile .memberdiv {
			width: 50%;
			margin-left: 0;
			margin-right: 0
		}
	}
</style>
</head>
<body>
<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
<div class="main-container" id="main-container">
	<div class="main-container-inner">
		<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
		<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb">
						<li>
							<i class="icon-home home-icon"></i>
							<a href="#">首页</a>
						</li>
						<li>
							<a href="#">注册管理</a>
						</li>
						<li>
							<a href="#">节点注册</a>
						</li>
						<li class="active">列表</li>
					</ul>
				 </div>
				 <div class="page-content">
				  	<div class="row">
				  		<div class="col-xs-12">
				  			<div class="row" style="height: 30px;">
				  				<input type="hidden" id="nodeId" name="nodeId" value="">
				  				<input type="hidden" id="nodeNetType" name="nodeNetType" value="">
				  				<input type="hidden" id="localNodeId" name="localNodeId" value="">
				  				<input type="hidden" id="pid" name="pid" value="">
								<button type="button" class="btn btn-sm btn-light" disabled="disabled" onclick="nodeAdd();"
									id="add">
									<i class="icon-cogs bigger-120"></i>注册子节点
								</button>
								<button type="button" class="btn btn-sm btn-light" disabled="disabled" onclick="nodeUpdate();"
									id="edit">
									<i class="icon-pencil bigger-120"></i>修改
								</button>
								<button type="button" class="btn btn-sm btn-light" disabled="disabled" onclick="nodeDel();"
									id="del">
									<i class="icon-trash bigger-120"></i>删除
								</button>
							<label ><i class='red'>${errorMsg }</i></label>
				  			</div>
						  	<div class="hr hr12 hr-dotted"></div>
						  	<div>
							  	<div class="col-xs-12">
							  		<div class="col-lg-4 col-md-4 col-sm-5 col-xs-11">
							  		  	<div class="table-responsive">
										  	<div id="treeDiv" >		
												<div class="zTreeDemoBackground" >
													<ul id="treeDemo" class="ztree" ></ul>
												</div>
											</div>
									  	</div>
							  		</div>
							  		<div class="col-lg-8 col-md-8 col-sm-7 col-xs-11">
							  			<div   id="data">
								  		</div>
							  		</div>
							  	</div>
						  	</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>
